$(function(){
//	随访日期
	var today = new Date();
	var followDate = new mui.DtPicker({
	    type: "date",//设置日历初始视图模式 
	    beginDate: new Date(1900, 01, 01),//设置开始日期 
	    endDate: new Date(today.getFullYear(),today.getMonth(),today.getDate()),//设置结束日期 
	}); 
	$("#followDate").click(function(){
	    followDate.show(function(items) {
	    	$("#followDate").text(items.value).css("color","#333");
	    	$("input[name='visitDate']").val(items.value);
		})  
    });
    
//	随访形式
	var formal = new mui.PopPicker();
	formal.setData([{
	    value: "1",
	    text: "门诊"
	}, {
	    value: "2",
	    text: "家庭访问"
	}, {
	    value: "3",
	    text: "电话"
	}, {
	    value: "4",
	    text: "失访"
	}, {
	    value: "5",
	    text: "死亡"
	}])
	$("#formal").click(function(){
		formal.show(function(item) {
			$("#formal").text(item[0].text).css("color","#333");
			if($("#formal").text()=="失访"){
				$(".form2").show();
				$(".form1").hide();
				$(".form3").hide();
			}else if($("#formal").text()=="死亡"){
				$(".form3").show();
				$(".form1").hide();
				$(".form2").hide();
			}else{
				$(".form1").show();
				$(".form2").hide();
				$(".form3").hide();
			}
			$("input[name='visitType']").val(item[0].value);
			$("#nextBtn").attr("data-id",item[0].value);
		})
	});
    
    
   //	失访
	var missing  = new mui.PopPicker();
	missing .setData([{
	    value: "1",
	    text: "外出打工"
	}, {
	    value: "2",
	    text: "迁居他处"
	}, {
	    value: "3",
	    text: "走失"
	}, {
	    value: "4",
	    text: "连续3次未访问到"
	}, {
	    value: "5",
	    text: "其他"
	}]);
	$("#missing").on("click",function(){
		missing.show(function(item) {
			$("#missing ").text(item[0].text).css("color","#333");
			$("input[name='loseInfo']").val(item[0].value);
		})
	});
	
		
	//死亡时间
	var deathTime = new mui.DtPicker({
	    type: "date",//设置日历初始视图模式 
	    beginDate: new Date(1900, 01, 01),//设置开始日期 
	    endDate: new Date(today.getFullYear(),today.getMonth(),today.getDate()),//设置结束日期 
	}); 
	$("#deathTime").click(function(){
	    deathTime.show(function(items) {
	    	$("#deathTime").text(items.value).css("color","#333");
	    	$("input[name='dieInfo[d_time]']").val(items.value);
		})  
   });
   
   //	死亡原因
	var causeDeath  = new mui.PopPicker();
	causeDeath .setData([{
	    value: "0",
	    text: "躯干疾病"
	}, {
	    value: "9",
	    text: "自杀"
	}, {
	    value: "10",
	    text: "他杀"
	}, {
	    value: "11",
	    text: "意外"
	}, {
	    value: "12",
	    text: "精神疾病相关并发症"
	}, {
	    value: "13",
	    text: "其他"
	}]);
	$("#causeDeath ").on("click",function(){
		causeDeath .show(function(item) {
			$("#causeDeath ").text(item[0].text).css("color","#333");
			if($("#causeDeath ").text()=="躯干疾病"){
				$("#trunkDisease ").show();
			}else{
				$("#trunkDisease ").hide();
			}
			$("input[name='dieInfo[d_why]']").first().val(item[0].value);
		})
	});
	
//	危险性
	var danger = new mui.PopPicker();
	danger.setData([{
	    value: "0",
	    text: "0级"
	}, {
	    value: "1",
	    text: "1级"
	}, {
	    value: "2",
	    text: "2级"
	}, {
	    value: "3",
	    text: "3级"
	}, {
	    value: "4",
	    text: "4级"
	}, {
	    value: "5",
	    text: "5级"
	}])
	$("#danger").click(function(){
		danger.show(function(item) {
			$("#danger").text(item[0].text).css("color","#333");
			$("input[name='socialInfo[grades]']").val(item[0].value);
		})
	});
	/*危险性目前症状*/
 	$("input[name='riskInfo[qt]']").on("click",function(){
 		var $this=$(this).is(":checked");
 		if($this){
 			$(".writeRemarks0").show();
			$(".writeRemarks0 input").removeAttr("disabled");
 		}else{
 			$(".writeRemarks0").hide();
			$(".writeRemarks0 input").attr("disabled",true);
 		}
// 		var inputSymptom=$("input[name='riskInfo[symptom]']");
// 		console.log(inputSymptom.length)
// 		for(i in inputSymptom){
// 			if(inputSymptom[i].checked){
// 				console.log(inputSymptom[i].value);
// 				if(inputSymptom[i].value==12){
// 					$(".writeRemarks0").show();
//					$(".writeRemarks0 input").removeAttr("disabled");
// 				}else{
// 					$(".writeRemarks0").hide();
//					$(".writeRemarks0 input").attr("disabled",true);
// 				}
// 			}
// 		}
 	});

//	自知力
	var knowledge = new mui.PopPicker();
	knowledge.setData([{
	    value: "1",
	    text: "自知力完全"
	}, {
	    value: "2",
	    text: "自知力不完全"
	}, {
	    value: "3",
	    text: "自知力缺失"
	}])
	$("#knowledge").click(function(){
		knowledge.show(function(item) {
			$("#knowledge").text(item[0].text).css("color","#333");
			$("input[name='perception']").val(item[0].value);
		})
	});
//	睡眠状况
	var excellent = new mui.PopPicker();
	excellent.setData([{
	    value: "1",
	    text: "良好"
	}, {
	    value: "2",
	    text: "一般"
	}, {
	    value: "3",
	    text: "较差"
	}])
	$(".excellent").click(function(){
		excellent.pickers[0].setSelectedIndex(0);
		var $this = $(this);
		excellent.show(function(item) {
			$this.text(item[0].text).css("color","#333");
			$("input[name='sleepStatus']").val(item[0].value);
		})
	});
	$(".excellent1").click(function(){
		excellent.pickers[0].setSelectedIndex(0);
		var $this = $(this);
		excellent.show(function(item) {
			$this.text(item[0].text).css("color","#333");
			$("input[name='dietaryStatus']").val(item[0].value);
		})
	});
	$(".excellent2").click(function(){
		excellent.pickers[0].setSelectedIndex(0);
		var $this = $(this);
		excellent.show(function(item) {
			$this.text(item[0].text).css("color","#333");
			$("input[name='socialInfo[shenghuo]']").val(item[0].value);
		})
	});
	$(".excellent3").click(function(){
		excellent.pickers[0].setSelectedIndex(0);
		var $this = $(this);
		excellent.show(function(item) {
			$this.text(item[0].text).css("color","#333");
			$("input[name='socialInfo[jiawu]']").val(item[0].value);
		})
	});
	$(".excellent4").click(function(){
		excellent.pickers[0].setSelectedIndex(0);
		var $this = $(this);
		excellent.show(function(item) {
			$this.text(item[0].text).css("color","#333");
			$("input[name='socialInfo[laodong]']").val(item[0].value);
		})
	});
	$(".excellent5").click(function(){
		excellent.pickers[0].setSelectedIndex(0);
		var $this = $(this);
		excellent.show(function(item) {
			$this.text(item[0].text).css("color","#333");
			$("input[name='socialInfo[xuexi]']").val(item[0].value);
		})
	});
	$(".excellent6").click(function(){
		excellent.pickers[0].setSelectedIndex(0);
		var $this = $(this);
		excellent.show(function(item) {
			$this.text(item[0].text).css("color","#333");
			$("input[name='socialInfo[jiaowang]']").val(item[0].value);
		})
	});
	
	
	//目前症状
	$("input[name='zhengzhuang']").on("click",function(){
		var $this = $(this).val();
		var id = $(this).is(":checked");
		if(id&&$this<7){
			$(this).parent().parent().next().find("input").eq(0).removeAttr("disabled");
			var lists =$("input[name='zhengzhuang']").eq(6);
			lists.prop("checked", false);
		}else{
			$(this).parent().parent().next().find("input").eq(0).attr("disabled",true);
		}
		if(id&&$this==7){
			$(".getsymptomInfo").attr("disabled",true);
			$(".getsymptomInfo").val("");
			var lists =$(this).parent().parent().siblings().find("input[name='zhengzhuang']");
			lists.prop("checked", false);
			console.log(lists);
		}
	});
	
//	关锁情况
	var closeLock = new mui.PopPicker();
	closeLock.setData([{
	    value: "1",
	    text: "无关锁"
	}, {
	    value: "2",
	    text: "关锁"
	}, {
	    value: "3",
	    text: "关锁已解除"
	}])
	$("#closeLock").click(function(){
		closeLock.show(function(item) {
			$("#closeLock").text(item[0].text).css("color","#333");
			$("input[name='isBelock']").val(item[0].value);
		})
	});
	
	
//	住院情况
	var Hospitalization = new mui.PopPicker();
	Hospitalization.setData([{
	    value: "0",
	    text: "未住院"
	}, {
	    value: "1",
	    text: "目前正在住院"
	}, {
	    value: "2",
	    text: "曾住院，现未住院"
	}])
	$("#Hospitalization").click(function(){
		Hospitalization.show(function(item) {
			$("#Hospitalization").text(item[0].text).css("color","#333");
			$("input[name='inHospital']").val(item[0].value);
			if($("#Hospitalization").text()=="曾住院，现未住院"){
					$(".leaveTime").show();
				}else{
					$(".leaveTime").hide();
				}
		});
	});
	//	末次出院日期
	var leaveTime = new mui.DtPicker({
	    type: "date",//设置日历初始视图模式 
	    beginDate: new Date(1900, 01, 01),//设置开始日期 
	    endDate: new Date(today.getFullYear(),today.getMonth(),today.getDate()),//设置结束日期 
	}); 
	$("#leaveTime").click(function(){
	    leaveTime.show(function(items) {
	    	$("#leaveTime").text(items.value).css("color","#333");
	    	$("input[name='leaveHosDate']").val(items.value);
		})  
   });
   
//	服药依从性
	var Medication = new mui.PopPicker();
	Medication.setData([{
	    value: "1",
	    text: "按医嘱规律服药"
	}, {
	    value: "2",
	    text: "间歇服药"
	}, {
	    value: "3",
	    text: "不服药"
	}, {
	    value: "4",
	    text: "医嘱勿需服药"
	}])
	$("#Medication").click(function(){
		Medication.show(function(item) {
			$("#Medication").text(item[0].text).css("color","#333");
			$("input[name='otherInfo[yilaxing]']").val(item[0].value);
		})
	});
	
//	治疗效果
	var treatment  = new mui.PopPicker();
	treatment .setData([{
	    value: "1",
	    text: "痊愈"
	}, {
	    value: "2",
	    text: "好转"
	}, {
	    value: "3",
	    text: "无变化"
	}, {
	    value: "4",
	    text: "加量"
	}])
	$("#treatment ").click(function(){
		treatment .show(function(item) {
			$("#treatment ").text(item[0].text).css("color","#333");
			$("input[name='otherInfo[xiaoguo]']").val(item[0].value);
		})
	});
	
	
	//	下次随访分类
	var ThisFollowUp  = new mui.PopPicker();
	ThisFollowUp .setData([{
	    value: "1",
	    text: "不稳定"
	}, {
	    value: "2",
	    text: "基本稳定"
	}, {
	    value: "3",
	    text: "稳定"
	}])
	$("#ThisFollowUp ").click(function(){
		ThisFollowUp .show(function(item) {
			$("#ThisFollowUp ").text(item[0].text).css("color","#333");
			$("input[name='nextClassify']").val(item[0].value);
		})
	});
	
//	下次随访时间
	var nextTime = new mui.DtPicker({
	    type: "date",//设置日历初始视图模式 
	    beginDate: new Date(today.getFullYear(),today.getMonth(),today.getDate()),//设置开始日期 
	    endDate: new Date(today.getFullYear()+1,today.getMonth(),today.getDate()),//设置结束日期 
	}); 
	$("#nextTime").click(function(){
	    nextTime.show(function(items) {
	    	$("#nextTime").text(items.value).css("color","#333");
	    	$("input[name='nextDate']").val(items.value);
		})  
   });
   
	/*实验室检查*/
	$("input[name='otherInfo[jiancha]']").on("click",function(e){
 		var inputSymptom=$("input[name='otherInfo[jiancha]']");
 		console.log(inputSymptom.length)
 		for(i in inputSymptom){
 			if(inputSymptom[i].checked){
 				console.log(inputSymptom[i].value);
 				if(inputSymptom[i].value==2){
 					$(".writeRemarks1").show();
					$(".writeRemarks1 input").removeAttr("disabled");
 				}else{
 					$(".writeRemarks1").hide();
					$(".writeRemarks1 input").attr("disabled",true);
 				}
 			}
 		}
 	});
	
	
	
	/*药物不良反应*/
	$("input[name='otherInfo[fanying]']").on("click",function(e){
 		var inputSymptom=$("input[name='otherInfo[fanying]']");
 		console.log(inputSymptom.length)
 		for(i in inputSymptom){
 			if(inputSymptom[i].checked){
 				console.log(inputSymptom[i].value);
 				if(inputSymptom[i].value==2){
 					$(".writeRemarks2").show();
					$(".writeRemarks2 input").removeAttr("disabled");
 				}else{
 					$(".writeRemarks2").hide();
					$(".writeRemarks2 input").attr("disabled",true);
 				}
 			}
 		}
 	});
	
	/*是否转诊断*/
	$("input[name='otherInfo[zhuanzhen]']").on("click",function(e){
 		var inputSymptom=$("input[name='otherInfo[zhuanzhen]']");
 		console.log(inputSymptom.length)
 		for(i in inputSymptom){
 			if(inputSymptom[i].checked){
 				console.log(inputSymptom[i].value);
 				if(inputSymptom[i].value==2){
 					$(".treatment-list").show();
					$(".treatment-list input").removeAttr("disabled");
 				}else{
 					$(".treatment-list").hide();
					$(".treatment-list input").attr("disabled",true);
 				}
 			}
 		}
 	});
	
	

	/*康复措施*/
	$("input[name='recuperateMethod[qt]']").on("click",function(){
		var $this = $(this).is(":checked");
		if($this){
			$(".writeRemarks3").show();
			$(".writeRemarks3 input").removeAttr("disabled");
		}else{
			$(".writeRemarks3").hide();
			$(".writeRemarks3 input").attr("disabled",true);
		}
	});
   
   
	
//	添加用药情况

	$("#addMedicine").on("click",function(){
		var html="";
		var i = $(this).data("id");
		if(i>=3){
			mui.alert("只能添加三条");
			return false;
		}
		html += '<div class="medicineList">'
					+'<div class="mui-input-row">'
						+'<label>药物名</label>'
						+'<input type="text" placeholder="请输入" class="textR" name="pharmacyInfo[name]['+i+']">'
					+'</div>'
					+'<div class="mui-input-row">'
						+'<label>用法</label>'
						+'<div class="medicine">'
							+'<span>每日</span>'
							+'<input type="number" placeholder="0"  name="pharmacyInfo[cishu]['+i+']">'
							+'<font>次</font>'
						+'</div>'
					+'</div>'
					+'<div class="mui-input-row">'
						+'<label>每次剂量</label>'
						+'<div class="medicine">'
							+'<input type="number" placeholder="0"  name="pharmacyInfo[jiliang]['+i+']">'
							+'<font>mg</font>'
						+'</div>'
					+'</div>'
				+'</div>';	
		i = parseInt(i)+1;
		$(".MedicineBox").append(html);
		$(this).attr("data-id",i)
	});
//	删除用药情况
	$("#deleteMedicine").click(function(){
		var id = parseInt($("#addMedicine").data("id"))-1;
		if(id>=0){
			var index=$(".MedicineBox").find(".medicineList").eq(id).remove();
			$("#addMedicine").attr("data-id",id)
		}
		
	});
//	添加用药指导

	$("#addMedicineUse").on("click",function(){
		var html="";
		var i = $(this).data("id");
		if(i>=3){
			mui.alert("只能添加三条");
			return false;
		}
		html += '<div class="medicineList">'
					+'<div class="mui-input-row">'
						+'<label>药物名</label>'
						+'<input type="text" placeholder="请输入" class="textR" name="guidanceInfo[name]['+i+']">'
					+'</div>'
					+'<div class="mui-input-row">'
						+'<label>用法</label>'
						+'<div class="medicine">'
							+'<span>每日</span>'
							+'<input type="number" placeholder="0"  name="guidanceInfo[cishu]['+i+']">'
							+'<font>次</font>'
						+'</div>'
					+'</div>'
					+'<div class="mui-input-row">'
						+'<label>每次剂量</label>'
						+'<div class="medicine">'
							+'<input type="number" placeholder="0"  name="guidanceInfo[jiliang]['+i+']">'
							+'<font>mg</font>'
						+'</div>'
					+'</div>'
				+'</div>';	
		i = parseInt(i)+1;
		$(".MedicineUse").append(html);
		$(this).attr("data-id",i)
	});
//	删除用药指导
	$("#deleteMedicineUse").click(function(){
		var id = parseInt($("#addMedicineUse").data("id"))-1;
		if(id>=0){
			var index=$(".MedicineUse").find(".medicineList").eq(id).remove();
			$("#addMedicineUse").attr("data-id",id)
		}
		
	});
	
	$("#nextBtn").on("click",function(){
		var id = Number($(this).data("id"));
		var visitDate = $("input[name='visitDate']").val();
		var visitType = $("input[name='visitType']").val();
		var archivesid =utilModule.getQueryString("archivesid");
		var uid = USERID?USERID:utilModule.getQueryString("uid");
		var param_first = "&visitDate="+visitDate+"&visitType="+visitType+"&patientid="+uid+"&archivesid="+archivesid;
		var i =checkinput(id);
		if(!i){
			return false;
		}
		if(0<id && id<4){
			var json_info =$('#form').serializeJSON();
			var a=[];// {"name":"123","cishu":"123","jiliang":"123"}
			var j=[];
			for (name1 in json_info.pharmacyInfo) {
				for (data in json_info.pharmacyInfo[name1] ) {
					if(!$.isArray(a[data])){
						a[data] =Array(3);
					}
					a[data][name1]=json_info.pharmacyInfo[name1][data];
					console.log(a);
				}
			}
			// {"0":"{'name':'123','1':'3','jiliang':'22'}","1":"{'name':'wda','cishu':'4f','jiliang':'asd'}"}
			// "{"0":"{'name':'123','1':'3','jiliang':'22'}","1":"{'name':'wda','cishu':'4f','jiliang':'asd'}"}";
			var html1="";
			for (b in a) {
				console.log(b);
				var html = "";
				
				for(c in a[b]){
					html+="\\\""+c+"\\\":\\\""+a[b][c]+"\\\",";
				}
				console.log(html);
				html1 += '"'+b+'":"{'+html.substring(0,html.length-1)+'}",';
			}
			//获取用药情况json
			var pharmacyInfo = "{"+html1.substring(0,html1.length-1)+"}";
			
			for (name1 in json_info.guidanceInfo) {
				for (data in json_info.guidanceInfo[name1] ) {
					if(!$.isArray(j[data])){
						j[data] =Array(3);
					}
					j[data][name1]=json_info.guidanceInfo[name1][data];
					console.log(j);
				}
			}
			var html2="";
			for (b in j) {
				console.log(b);
				var html = "";
				
				for(c in j[b]){
					html+="\\\""+c+"\\\":\\\""+j[b][c]+"\\\",";
				}
				console.log(html);
				html2 += '"'+b+'":"{'+html.substring(0,html.length-1)+'}",';
			}
			//获取用药指导json
			var guidanceInfo = "{"+html2.substring(0,html2.length-1)+"}";
			
			var param ="dietaryStatus="+json_info.dietaryStatus+"&inHospital="+json_info.inHospital+"&isBelock="+json_info.isBelock+"&leaveHosDate="+json_info.leaveHosDate+"&nextClassify="+json_info.nextClassify+"&nextDate="+json_info.nextDate+"&perception="+json_info.perception+"&recuperateMethod="+JSON.stringify(json_info.recuperateMethod)+"&sleepStatus="+json_info.sleepStatus+"&otherInfo="+JSON.stringify(json_info.otherInfo)+"&pharmacyInfo="+pharmacyInfo+"&guidanceInfo="+guidanceInfo+"&riskInfo="+JSON.stringify(json_info.riskInfo)+"&socialInfo="+JSON.stringify(json_info.socialInfo)+"&symptomInfo="+JSON.stringify(json_info.symptomInfo)+param_first;	

		}else if (id ==4){

			var param =$('#form4').serialize()+param_first;
			
		}else if (id ==5){
			var json_dieinfo =$('#form5').serializeJSON();
			var param ="dieInfo="+JSON.stringify(json_dieinfo.dieInfo)+param_first;	
		}
		electronicArchivesMdule.savepatientvisit(param,callBack);
		console.log(param);
		function callBack(data){
			console.log(data);
			if(data.result == 1){
				if(USERID == null){
					location.href = 'xyyl://xyyl_app/?{"id":"'+data.patientVisitInfo.id+'"}'
				}
				
				mui.alert("添加成功","提示","确定",function(){location.href = "./electronic-archives.html?archivesid="+archivesid})
			}
		}
	});
	var infoid = utilModule.getQueryString("infoid");
	if(utilModule.checkUndefined(infoid)!="") {
		var param = {"infoid":infoid};
		electronicArchivesMdule.patientvisitinfo(param,function(data){
			console.log(data);
			var info = data.patientVisitInfo;
			console.log(info);
			console.log(info.visitDate);
			var Year = new Date().getFullYear();
			var month = new Date().getMonth()+1;       //获取当前月份(0-11,0代表1月)
			var date = new Date().getDate(); //获取当前日(1-31)
			var date = date >10 ? date : "0" +date;
			var month = month>10? month : "0"+month;
			var currentTime = Year+"-"+month+"-"+date;
			console.log(currentTime);
			$("#nextBtn").attr("data-id",info.visitType);
			$("#nextBtn").attr("data-archivesid",info.archivesid);
			$("#followDate").text(currentTime).css("color","#333");
			$("input[name='visitDate']").val(currentTime);
			var sfType=["门诊","家庭访问","电话","失访","死亡"];
			$("#formal").text(sfType[info.visitType-1]).css("color","#333");
			$("input[name='visitType']").val(info.visitType);
			if(info.visitType==4){
				$(".form2").show();
			}else if(info.visitType==5){
				$(".form3").show();
			}else{
				$(".form1").show();
			}
			var zsInfo=["外出打工","迁居他处","走失","连续3次未访问到","其他"];
			if(info.loseInfo!=""){
				$("#missing").text(zsInfo[info.loseInfo-1]).css("color","#333");
			}
			if(!info.dieInfo == ""){
				var dieTime=JSON.parse(info.dieInfo);
				$("#deathTime").text(dieTime.d_time).css("color","#333");
				var dieWhy=["躯干疾病","染病和寄生虫病","肿瘤","心脏病","脑血管病","呼吸系统疾病","消化系统疾病","其他疾病","不详","自杀","他杀","意外","精神疾病相关并发症","其他"];
				if(0<=dieTime.d_why&&dieTime.d_why<=8){
					$("#causeDeath").text("躯干疾病").css("color","#333");
					$("#trunkDisease").show();
					var obj =$("input[name='dieInfo[d_why]']");
					for (one in obj ) {
						if(obj.eq(one).val()==dieTime.d_why){
							obj.eq(one).attr("checked",true);
						}
					}
				}else{
					$("#causeDeath").text(dieWhy[dieTime.d_why]).css("color","#333");
					$("#trunkDisease").hide();
				}
			}
			if(!info.riskInfo == ""){
				var wxRisk=JSON.parse(info.riskInfo);
				for(i in wxRisk){
					if(wxRisk[i]-1==11){
						$(".writeRemarks0").show();
						$(".writeRemarks0 input").removeAttr("disabled");
						$(".writeRemarks0 input").val(wxRisk.write);
					}
					$("input[data-type='wxmqzz']").eq(wxRisk[i]-1).prop("checked",true);
				}
			}
			if(!info.perception == ""){
				var zzPerception=["自知力完全","自知力不全","自知力缺失"];
				$("#knowledge").text(zzPerception[info.perception-1]).css("color","#333");
				$("input[name='perception']").val(info.perception);
			}
			if(!info.sleepStatus == ""){
				var smSleep=["良好","一般","较差"];
				$(".excellent").text(smSleep[info.sleepStatus-1]).css("color","#333");
				$("input[name='sleepStatus']").val(info.sleepStatus);
			}
			if(!info.dietaryStatus == ""){
				var ysStatus=["良好","一般","较差"];
				$(".excellent1").text(ysStatus[info.dietaryStatus-1]).css("color","#333");
				$("input[name='dietaryStatus']").val(info.dietaryStatus);
			}
			if(!info.socialInfo == ""){
				var social=JSON.parse(info.socialInfo);
				var grades=["0级","1级","2级","3级","4级","5级"];
				$("#danger").text(grades[social.grades]).css("color","#333");
				$("input[name='socialInfo[grades]']").val(social.grades);
				var ysStatus=["良好","一般","较差"];
				$(".excellent2").text(ysStatus[social.shenghuo-1]).css("color","#333");
				$("input[name='socialInfo[shenghuo]']").val(social.shenghuo);
				$(".excellent3").text(ysStatus[social.jiawu-1]).css("color","#333");
				$("input[name='socialInfo[jiawu]']").val(social.jiawu);
				$(".excellent4").text(ysStatus[social.laodong-1]).css("color","#333");
				$("input[name='socialInfo[laodong]']").val(social.laodong);
				$(".excellent5").text(ysStatus[social.xuexi-1]).css("color","#333");
				$("input[name='socialInfo[xuexi]']").val(social.xuexi);
				$(".excellent6").text(ysStatus[social.jiaowang-1]).css("color","#333");
				$("input[name='socialInfo[jiaowang]']").val(social.jiaowang);
			}
			if(info.symptomInfo=="undefined"||info.symptomInfo==""){
				var obj =$("input[name='zhengzhuang']");
				$($(obj)[obj.length-1]).attr("checked",true);
			}else{
				var mqSymptoms=JSON.parse(info.symptomInfo);
				for(i in mqSymptoms){
					$("input[name='symptomInfo["+i+"]']").val(mqSymptoms[i]).removeAttr("disabled");
					$("input[name='symptomInfo["+i+"]']").parent().parent().prev().find("input").attr("checked",true);
				}
			}
			if(!info.isBelock==""){
				var lock=["无关锁","关锁","关锁已解除"];
				$("#closeLock").text(lock[info.isBelock-1]).css("color","#333");
				$("input[name='isBelock']").val(info.isBelock);
			}
			if(!info.inHospital==""){
				var lock=["未住院","目前正在住院","曾住院，现未住院"];
				$("#Hospitalization").text(lock[info.inHospital]).css("color","#333");
				$("input[name='inHospital']").val(info.inHospital);
				if(info.inHospital==3){
					$(".leaveTime").show();
					$("#leaveTime").text(info.leaveHosDate).css("color","#333");
					$("input[name='leaveHosDate']").val(info.leaveHosDate);
				}
			}
			if(!info.otherInfo==""){
				var other=JSON.parse(info.otherInfo);
				if(other.jiancha==1){
					$("input[name='otherInfo[jiancha]']").eq(1).attr("checked",true);
					$(".writeRemarks1").show();
					$(".writeRemarks1 input").val(other.jcDetail).removeAttr("disabled");
				}else{
					$("input[name='otherInfo[jiancha]']").eq(0).attr("checked",true);
				}
				var compliance=["按医嘱规律服药","间歇服药","不服药","医嘱勿需服药"];
				$("#Medication").text(compliance[other.yilaxing-1]).css("color","#333");
				$("input[name='otherInfo[yilaxing]']").val(other.yilaxing);
				if(other.fanying==0){
					$("input[name='otherInfo[fanying]']").eq(0).attr("checked",true);
				}else{
					$("input[name='otherInfo[fanying]']").eq(1).attr("checked",true);
					$(".writeRemarks2").show();
					$(".writeRemarks2 input").val(other.fyDetail).removeAttr("disabled");
				}
				var effect=["痊愈","好转","无变化","加量"];
				$("#treatment").text(effect[other.xiaoguo-1]).css("color","#333");
				$("input[name='otherInfo[xiaoguo]']").val(other.xiaoguo);
				if(other.zhuanzhen==2){
					$("input[name='otherInfo[zhuanzhen]']").eq(1).attr("checked",true);
					$(".treatment-list").show();
					$(".treatment-list input").removeAttr("disabled");
					$("input[name='otherInfo[yuanyin]']").val(other.yuanyin);
					$("input[name='otherInfo[keshi]']").val(other.keshi);
				}else{
					$("input[name='otherInfo[zhuanzhen]']").eq(0).attr("checked",true);
				}
			}
			if(info.pharmacyInfo!="undefined" &&info.pharmacyInfo !=""){
				var html = "";
				var i = 0;
				var data = JSON.parse(info.pharmacyInfo);
				for (a in data) {
					var ma =  JSON.parse(data[a]);
					html += '<div class="medicineList">'
								+'<div class="mui-input-row">'
									+'<label>药物名</label>'
									+'<input type="text" placeholder="请输入" class="textR" name="pharmacyInfo[name]['+a+']" value="'+ma.name+'">'
								+'</div>'
								+'<div class="mui-input-row">'
									+'<label>用法</label>'
									+'<div class="medicine">'
										+'<span>每日</span>'
										+'<input type="number" placeholder="0"  name="pharmacyInfo[cishu]['+a+']" value="'+ma.cishu+'">'
										+'<font>次</font>'
									+'</div>'
								+'</div>'
								+'<div class="mui-input-row">'
									+'<label>每次剂量</label>'
									+'<div class="medicine">'
										+'<input type="number" placeholder="0"  name="pharmacyInfo[jiliang]['+a+']" value="'+ma.jiliang+'">'
										+'<font>mg</font>'
									+'</div>'
								+'</div>'
							+'</div>';	
					i++;
				}
				$(".MedicineBox").append(html);
				$("#addMedicine").attr("data-id",i)
			}
			if(info.guidanceInfo!="undefined" &&info.guidanceInfo !=""){
				var html = "";
				var i = 0;
				var data = JSON.parse(info.guidanceInfo);
				for (a in data) {
					var ma =  JSON.parse(data[a]);
					html += '<div class="medicineList">'
								+'<div class="mui-input-row">'
									+'<label>药物名</label>'
									+'<input type="text" placeholder="请输入" class="textR" name="guidanceInfo[name]['+a+']" value="'+ma.name+'">'
								+'</div>'
								+'<div class="mui-input-row">'
									+'<label>用法</label>'
									+'<div class="medicine">'
										+'<span>每日</span>'
										+'<input type="number" placeholder="0"  name="guidanceInfo[cishu]['+a+']" value="'+ma.cishu+'">'
										+'<font>次</font>'
									+'</div>'
								+'</div>'
								+'<div class="mui-input-row">'
									+'<label>每次剂量</label>'
									+'<div class="medicine">'
										+'<input type="number" placeholder="0"  name="guidanceInfo[jiliang]['+a+']" value="'+ma.jiliang+'">'
										+'<font>mg</font>'
									+'</div>'
								+'</div>'
							+'</div>';	
					i++;
				}
				$(".MedicineUse").append(html);
				$("#addMedicineUse").attr("data-id",i)
			}
			if(!info.recuperateMethod==""){
				var method=JSON.parse(info.recuperateMethod);
				for(i in method){
					console.log(i)
					console.log(method[i])
					if(method[i]-1==4){
						$(".writeRemarks3").show();
						$(".writeRemarks3 input").removeAttr("disabled");
						$(".writeRemarks3 input").val(method.Detail);
					}
					$("input[data-type='kfmqzz']").eq(method[i]-1).prop("checked",true);
				}
//				var obj =$("input[name='recuperateMethod[select]']");
//				for(list in obj){
//					if(obj.eq(list).val()==method.select){
//							obj.eq(list).attr("checked",true);
//					}
//				}
//				if(method.select==5){
//					$(".writeRemarks3").show();
//					$(".writeRemarks3 input").val(method.Detail).removeAttr("disabled");
//				}
			}
			if(!info.nextClassify==""){
				var nextClass=["不稳定","基本稳定","稳定"];
				$("#ThisFollowUp").text(nextClass[info.nextClassify-1]).css("color","#333");
				$("input[name='nextClassify']").val(info.nextClassify);
			}
			if(!info.nextDate==""){
				$("#nextTime").text(info.nextDate).css("color","#333");
				$("input[name='nextDate']").val(info.nextDate);
			}
			
		})
		
	}
	
	
	
	
	
	/*表单验证*/
	function checkinput(id){
		var visitDate = $("input[name='visitDate']").val();
		var visitType = $("input[name='visitType']").val();
		if(visitDate==""){
			mui.alert("请选择随访日期");
			return false;
		}
		if(visitType==""){
			mui.alert("请选择随访形式");
			return false;
		}
		if(0<id && id<4){
			var grades = $("input[name='socialInfo[grades]']").val();
			var symptom = $("input[data-type='wxmqzz']");
			var perception = $("input[name='perception']").val();
			var sleepStatus = $("input[name='sleepStatus']").val();
			var shenghuo = $("input[name='socialInfo[shenghuo]']").val();
			var jiawu = $("input[name='socialInfo[jiawu]']").val();
			var laodong = $("input[name='socialInfo[laodong]']").val();
			var xuexi = $("input[name='socialInfo[xuexi]']").val();
			var jiaowang = $("input[name='socialInfo[jiaowang]']").val();
			var zhengzhuang = $("input[name='zhengzhuang']").val();
			var isBelock = $("input[name='isBelock']").val();
			var inHospital = $("input[name='inHospital']").val();
			var leaveHosDate = $("input[name='leaveHosDate']").val();
			var jiancha = $("input[name='otherInfo[jiancha]']").val();
			var yilaxing = $("input[name='otherInfo[yilaxing]']").val();
			var dietaryStatus = $("input[name='dietaryStatus']").val();
			var jiancha1 = $("input[name='otherInfo[jiancha]']").val();
			var xiaoguo = $("input[name='otherInfo[xiaoguo]']").val();
			var zhuanzhen = $("input[name='otherInfo[zhuanzhen]']").val();
			var yuanyin = $("input[name='otherInfo[yuanyin]']").val();
			var keshi = $("input[name='otherInfo[keshi]']").val();
			var recuperateMethod = $("input[data-type='kfmqzz']").val();
			var nextClassify = $("input[name='nextClassify']").val();
			var nextDate = $("input[name='nextDate']").val();
			var dangerWrite= $("input[name='riskInfo[write]']").val();
			var sysWrite = $("input[name='otherInfo[jcDetail]']").val();
			var blfyWrite = $("input[name='otherInfo[fyDetail]']").val();
			var zzWrite1 = $("input[name='otherInfo[yuanyin]']").val();
			var zzWrite2 = $("input[name='otherInfo[keshi]']").val();
			var fyWrite = $("input[name='otherInfo[fyDetail]']").val();
			var kfWrite = $("input[name='recuperateMethod[Detail]']").val();
			if(dangerWrite.length>9){
				mui.alert("目前症状备注不能超过9个字！");
				return false;
			}
			if(sysWrite.length>26){
				mui.alert("实验室备注不能超过26个字！");
				return false;
			}
			if(zzWrite1.length>23){
				mui.alert("转诊原因不能超过23个字！");
				return false;
			}
			if(zzWrite2.length>23){
				mui.alert("转诊医院不能超过23个字！");
				return false;
			}
			if(fyWrite.length>11){
				mui.alert("药物不良反应不能超过11个字！");
				return false;
			}
			if(kfWrite.length>38){
				mui.alert("康复措施不能超过38个字！");
				return false;
			}
			if(grades==""){
				mui.alert("请选择危险性");
				return false;
			}
			var symptomi =0
			symptom.each(function(){
			    if($(this).is(':checked')||$(this).val()==0){
			        symptomi=1;			    
				    if($(this).val()==12 && $("input[data-type='wxmqzz']").eq(12).val()==""){
				    	mui.alert("填写目前症状 备注");
				    	return false;
				    }
			    }
			});
			if(symptomi==0){
		    	mui.alert("请选择危险性目前症状");
				return false;
			}

			if(dietaryStatus==""){
				mui.alert("请选择饮食状况");
				return false;
			}
			if(perception==""){
				mui.alert("请选择自知力");
				return false;
			}
			if(sleepStatus==""){
				mui.alert("请选择睡眠状况");
				return false;
			}
			if(shenghuo==""){
				mui.alert("请选择个人生活料理");
				return false;
			}
			if(jiawu==""){
				mui.alert("请选择家务劳动");
				return false;
			}
			if(laodong==""){
				mui.alert("请选择生产劳动及工作");
				return false;
			}
			if(xuexi==""){
				mui.alert("请选择学习能力");
				return false;
			}
			if(jiaowang==""){
				mui.alert("请选择社会人际交往");
				return false;
			}
			if(zhengzhuang==""){
				mui.alert("请选择目前症状");
				return false;
			}
			if(isBelock==""){
				mui.alert("请选择随访期间关锁情况");
				return false;
			}
			if(inHospital==""){
				mui.alert("请选择随访期间住院情况");
				return false;
			}
			if(leaveHosDate=="" && inHospital ==3){
				mui.alert("请选择末次出院时间");
				return false;
			}
			if(jiancha==""){
				mui.alert("请选择实验室检查");
				return false;
			}
			if(yilaxing==""){
				mui.alert("请选择用药依从性");
				return false;
			}
			if(xiaoguo==""){
				mui.alert("请选择治疗效果");
				return false;
			}
			if(zhuanzhen==""){
				mui.alert("请选择是否转诊");
				return false;
			}else if(zhuanzhen=="2"){
				if(yuanyin==""){
					mui.alert("请填写转诊原因");
					return false;
				}
				if(keshi==""){
					mui.alert("请填写转诊至机构及科室");
					return false;
				}
			}
			if(recuperateMethod==""){
				mui.alert("请选择康复措施");
				return false;
			}
			if(recuperateMethod==5){
				var $num=$("input[name='recuperateMethod[Detail]']").val()
				if($num==""){
					mui.alert("请填写康复详情");
					return false;
				}
			}
			if(nextClassify==""){
				mui.alert("请选择下次随访分类");
				return false;
			}
			if(nextDate==""){
				mui.alert("请选择下次访问时间");
				return false;
			}
			if(jiancha1==""){
				mui.alert("请填写用药依从性详情");
				return false;
			}
			
		}else if (id ==4){
			var loseInfo = $("input[name='loseInfo']").val();
			if(loseInfo==""){
				mui.alert("请选择走失原因");
				return false;
			}
			
		}else if (id ==5){
			var d_time = $("input[name='dieInfo[d_time]']").val();
			var d_why = $("input[name='dieInfo[d_why]']").val();
			if(d_time==""){
				mui.alert("请选择死亡日期");
				return false;
			}
			if(d_why==""){
				mui.alert("请选择死亡原因");
				return false;
			}
			
		}
		return true;
	}
});